<?php
/*
  Plugin Name: WooCommerce ABF Shipping
  Plugin URI: http://illuminarepublications.com
  Description: WooCommerce ABF Shipping allows a store to obtain shipping rates for your orders dynamically via the ABF Shipping API.
  Version: 0.1
  Author: Benjamin Bloomfield
  Author URI: http://illuminarepublications.com

  Copyright: 2013 Benjamin Bloomfield.
  License: Public Domain
*/


/**
 * Required functions
 */
if ( ! function_exists( 'woothemes_queue_update' ) )
  require_once( 'woo-includes/woo-functions.php' );

/**
 * Plugin activation check
 */
function wc_abf_activation_check(){
  if ( ! function_exists( 'simplexml_load_string' ) ) {
        deactivate_plugins( basename( __FILE__ ) );
        wp_die( "Sorry, but you can't run this plugin, it requires the SimpleXML library installed on your server/hosting to function." );
  }
}

register_activation_hook( __FILE__, 'wc_abf_activation_check' );

/**
 * Localisation
 */
load_plugin_textdomain( 'wc_abf', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );

/**
 * Plugin page links
 */
function wc_abf_plugin_links( $links ) {

  $plugin_links = array(
    '<a href="' . admin_url( 'admin.php?page=woocommerce_settings&tab=shipping&section=WC_Shipping_ABF' ) . '">' . __( 'Settings', 'wc_abf' ) . '</a>'
  );

  return array_merge( $plugin_links, $links );
}

add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), 'wc_abf_plugin_links' );

/**
 * Check if WooCommerce is active
 */
if ( is_woocommerce_active() ) {

  /**
   * wc_abf_init function.
   *
   * @access public
   * @return void
   */
  function wc_abf_init() {
    include_once( 'classes/class-wc-shipping-abf.php' );
  }

  add_action( 'woocommerce_shipping_init', 'wc_abf_init' );

  /**
   * wc_abf_add_method function.
   *
   * @access public
   * @param mixed $methods
   * @return void
   */
  function wc_abf_add_method( $methods ) {
    $methods[] = 'WC_Shipping_ABF';
    return $methods;
  }

  add_filter( 'woocommerce_shipping_methods', 'wc_abf_add_method' );

  /**
   * wc_abf_scripts function.
   *
   * @access public
   * @return void
   */
  function wc_abf_scripts() {
    wp_enqueue_script( 'jquery-ui-sortable' );
  }

  add_action( 'admin_enqueue_scripts', 'wc_abf_scripts' );
}
